package com.kx.game.center.common;

import com.kx.core.dawn.dbs.dao.BaseDao;
import com.kx.core.dawn.dbs.dao.impl.GameServerDao;
import com.kx.core.dawn.dbs.dao.impl.GatewayDao;
import com.kx.core.dawn.dbs.dao.impl.RoleDao;
import com.kx.core.dawn.dbs.dao.impl.UserDao;
import java.util.HashMap;
import java.util.Map;

public enum DaoNameEnum {

    DAO1("Game_Server", GameServerDao.class),
    DAO2("Gateway", GatewayDao.class),
    DAO3("Role_Info", RoleDao.class),
    DAO4("User_Info", UserDao.class),
    ;

    private String tableName;
    private Class<? extends BaseDao> clazz;

    DaoNameEnum(String tableName, Class<? extends BaseDao> clazz) {
        this.tableName = tableName;
        this.clazz = clazz;
    }

    /**
     * 按索引顺序存放的枚举数组
     */
    private static final Map<Class<? extends BaseDao>, String> hashDaoName = DaoNameEnum.initEnum(DaoNameEnum.values());

    private static Map<Class<? extends BaseDao>, String> initEnum(DaoNameEnum[] enums) {
        Map<Class<? extends BaseDao>, String> hashMap = new HashMap<>();
        for (DaoNameEnum _enum : enums) {
            hashMap.put(_enum.getClazz(), _enum.getTableName());
        }
        return hashMap;
    }

    public static String getTableName(Class<? extends BaseDao> clazz) {
        return hashDaoName.get(clazz);
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public Class<? extends BaseDao> getClazz() {
        return clazz;
    }

    public void setClazz(Class<? extends BaseDao> clazz) {
        this.clazz = clazz;
    }

    public static Map<Class<? extends BaseDao>, String> getHashDaoName() {
        return hashDaoName;
    }
}
